package pro.shuangxi.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author mengshx
 * @description <p>文件相关工具类</p>
 * @date 2022-07-15 11:00
 **/
public class FileUtils {
    public static List<String> getFileRelativePath(File directory, String suffix) {
        List<String> pathList = new ArrayList<>();
        getPath(pathList, "", directory,suffix);
        return pathList;
    }

    private static void getPath(List<String> pathList, String path, File directory,String suffix) {
        for (File file : directory.listFiles()) {
            if (file.isDirectory()) {
                getPath(pathList,path+file.getName()+File.separator,file,suffix);
            }else {
                if (file.getName().contains(suffix)) {
                    pathList.add(path + file.getName());
                }
            }
        }

    }
}
